package uni.UNIBEE7B8D.view.Study.Zhibo.ZhiboList;


import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.LifecycleOwner;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import uni.UNIBEE7B8D.Adapter.RecycClickOnListener;
import uni.UNIBEE7B8D.Adapter.study.ZhiboRecycAdapter;
import uni.UNIBEE7B8D.Enty.CommonClass;
import uni.UNIBEE7B8D.Enty.HomeFriend;
import uni.UNIBEE7B8D.Enty.HomeMenu;
import uni.UNIBEE7B8D.Enty.HomeZhibo;
import uni.UNIBEE7B8D.Presenter.ZhiboListPersenter;
import uni.UNIBEE7B8D.R;
import uni.UNIBEE7B8D.view.Study.ZhiboContent.ZhiboContentActivity;


/**
 * A simple {@link Fragment} subclass.
 */
public class ZhiboListFragment extends Fragment implements ZhiboListContract.ZhiboListView{


    @BindView(R.id.zhiboList)
    RecyclerView zhiboList;

    private ZhiboListPersenter zhiboListPersenter = new ZhiboListPersenter(this);
    public ZhiboListFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_zhibo_list, container, false);
        ButterKnife.bind(this, view);//注意
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        zhiboListPersenter.GetZhibo();
    }

    @Override
    public void Toast(String s) {
        Toast.makeText(getActivity(), s, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void GetMeny(HomeMenu homeMenu) {

    }

    @Override
    public void GetZhibo(HomeZhibo homeZhibo) {
        Log.d("==",homeZhibo.getResult().toString());
        //--------直播-----------------
        List<HomeZhibo.ResultBean.RecordsBean> list = new ArrayList<>();
        list = homeZhibo.getResult().getRecords();

        // 设置布局管理器
        LinearLayoutManager linearLayoutManager1 = new LinearLayoutManager(getActivity(), RecyclerView.VERTICAL, false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        zhiboList.setLayoutManager(linearLayoutManager1);

        ZhiboRecycAdapter zhiboRecycAdapter = new ZhiboRecycAdapter(list, getActivity());
        zhiboList.setAdapter(zhiboRecycAdapter);
        zhiboRecycAdapter.setRecycClickOnListener(new RecycClickOnListener() {
            @Override
            public void onItemClick(HomeFriend.ResultBean commonClass) {

            }

            @Override
            public void onItemZhibo(HomeZhibo.ResultBean.RecordsBean commonClass) {
                Log.d("==", commonClass.getId() + "");
                Intent intent = new Intent(getActivity(), ZhiboContentActivity.class);
                intent.putExtra("id", commonClass.getId());
                startActivity(intent);
            }
        });

    }
}
